package acctest.fixture;
import java.awt.List;
import java.sql.SQLException;
import java.sql.Timestamp;

import run.ServerFrame;
import server.SimpleServer;
import client.Message;
import db.parking.beans.Customer;
import db.parking.beans.Orders;
import db.parking.beans.Sms;
import db.parking.beans.Subscriber;
import db.tables.AdminCustomer;
import db.tables.AdminOrders;
import db.tables.AdminSMS;
import fit.ActionFixture;


public class delayOrder extends ActionFixture {
	
	private ServerFrame server;
	private List liste = new List();
	private Orders o1;
	private SimpleServer simple;
	private Message msg = null;
	private Timestamp startTimestamp = null;
	private Timestamp leaveTimestamp = null;
	private Timestamp currTimestamp = null;

	
	
	public delayOrder() throws SQLException
	{
		server= new ServerFrame(12345);
		server.setDbUser("root");
		server.setDbPass("31387650");
		server.setDbHost("localhost");
		server.setDbName("vcp");
		server.setDbPort("3306");
		
		server.listen();
		msg = new Message();
		o1 = new Orders();
	}
	
	public void delayOrder()
	{
		long time = System.currentTimeMillis();// Set current time at this second to StartTime
		currTimestamp = new Timestamp(time);
		startTimestamp = new Timestamp(time);
		startTimestamp.setHours(startTimestamp.getHours()-1);
		leaveTimestamp = new Timestamp(time);
		leaveTimestamp.setHours(leaveTimestamp.getHours()+2);
	}
	
	
	
	public void changeTimes(int hours)
	{
		long time = System.currentTimeMillis();// Set current time at this second to StartTime
		currTimestamp = new Timestamp(time);
		startTimestamp = new Timestamp(time);
		leaveTimestamp = new Timestamp(time);
		startTimestamp.setHours(currTimestamp.getHours()+hours);
		leaveTimestamp.setHours(startTimestamp.getHours()+2);
		
		
	}
	public void CheckInTemporary() throws Exception {

	
		server.getServer().CheckInRegular(msg);
	}
		
	public void tempCustomerId(String cusID) throws Exception
	{
		o1.setUid(cusID);
		AdminCustomer.update(cusID, 0);
	}
	public void carNo(String carNo)
	{
		o1.setCarNo(carNo);
	}
	public void createTemporaryOrder(boolean sendSms) throws Exception
	{
	
		o1 = new Orders(o1.getUid(), "Temporary", o1.getCarNo(),
				startTimestamp, leaveTimestamp, 3, "e@e.com",0);
		System.out.println("start"+startTimestamp+",leaveTime:"+leaveTimestamp);
		msg.setObj(o1);
		server.getServer().AddTemporaryOrder(msg);
		o1 = AdminOrders.getRow(o1.getUid(),o1.getCarNo());//add oid
		//customer has answered sms and got fine
		if(sendSms == true)
		{	
			Sms sms = new Sms();
			sms.setCusID(o1.getUid());
			sms.setMessage("Please Tell Us If Your On Your Way?");
			sms.setoID(o1.getOid());
			sms.setStatus(4);
			AdminSMS.insert(sms, "Please Tell Us If Your On Your Way?", currTimestamp);
		}
	}
	public float checkOutFine() throws SQLException
	{
		msg.setObj(o1);
		server.getServer().CheckOut(msg);
		Customer c = AdminCustomer.getCustomerBalance(o1.getUid());
		return (float) c.getAmount();
	}
	
	
	

  }

